package com.besall.allbase.view.activity.chipstoollevel4.protocol.Settings;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.NumberPicker;
import android.widget.TextView;

import com.bes.sdk.utils.SettingsJsonUtils;

import java.util.Arrays;
import java.util.List;

import bb.lanxing.R;
import bb.lanxing.activity.base.BaseActivity;
import bb.lanxing.lib.devices.sgsettingentity.setting.PanelModel;
import bb.lanxing.util.CommonUtil;
import bb.lanxing.util.ui.GsonUtils;
import bb.lanxing.utils.PanelModelToJsonUtil;

public class DeviceReminder1Activity extends BaseActivity {
    private String device_model = "BC270";
    private String sn = "test";
    private int FACTOR = 5;

    private List<Integer> reminder = Arrays.asList(0, 0, 0, 0, 0, 0);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_reminder);

        ImageView back = findViewById(R.id.back);
        back.setOnClickListener(v -> onBackPressed());

        TextView title = findViewById(R.id.title);
        title.setText(getIntent().getStringExtra("title"));

        NumberPicker numberPicker = findViewById(R.id.wheelview);
        NumberPicker numberPickerMax = findViewById(R.id.wheelview1);

        int sportMode = getIntent().getIntExtra("sportMode", 0);
        PanelModel PANEL_MODEL = GsonUtils.Companion.getInstance().fromJson(getIntent().getStringExtra("PANEL_MODEL"), PanelModel.class);
        if (PANEL_MODEL != null) {
            reminder = PANEL_MODEL.getProfilesList().get(sportMode).getRemind();
        }
        numberPicker.setFormatter(value -> "" + value * 10);
        numberPicker.setMinValue(6);
        numberPicker.setMaxValue(15);
        numberPickerMax.setFormatter(value -> "" + value * 10);
        numberPickerMax.setMinValue(6);
        numberPickerMax.setMaxValue(15);
        FACTOR = 10;
        numberPicker.setValue(reminder.get(4) / FACTOR);
        numberPickerMax.setValue(reminder.get(5) / FACTOR);

        ImageView img_confirm = findViewById(R.id.img_confirm);
        img_confirm.setOnClickListener(v -> {
            reminder.set(4, numberPicker.getValue() * FACTOR);
            reminder.set(5, numberPickerMax.getValue() * FACTOR);
            String content = PanelModelToJsonUtil.toJson(PANEL_MODEL);
            device_model = SettingsJsonUtils.getDeviceModel(this);
            sn = SettingsJsonUtils.getSn(this);
            CommonUtil.saveDeviceProfile(content, device_model, sn);
            CommonUtil.sendPanelsJsonFile(context, device_model, sn);
            Intent intent = new Intent();
            intent.putExtra("PANEL_MODEL", PanelModelToJsonUtil.toJson(PANEL_MODEL));
            setResult(RESULT_OK, intent);
            finish();
        });
    }
}